package com.zkingsoft.actions.admin;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.model.PaginationVO;
import com.zkingsoft.model.Role;
import com.zkingsoft.model.RolePwoer;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.services.RolePwoerService;
import com.zkingsoft.services.RoleService;

/**
 * @project MatrixCms
 * @package com.zkingsoft.actions.admin
 * @class ShowBoxController.java
 * @author Matrix-J E-mail:<935090232@qq.com>
 * @date 2016年4月21日10:31
 * @description 展位管理
 */
@Controller
@RequestMapping(value = "/admin/role")
public class RoleController extends BaseController {

	private static final Logger log = Logger.getLogger(RoleController.class);

	@Resource
	private RoleService currentService;
	@Resource
	private RolePwoerService pwoerService;

	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(HttpServletRequest request, Role role, PaginationVO pageVo) {
		log.info("按钮列表...");
		role.setCompanyId(getMe(request).getCompanyId());
		return showList(currentService, role, pageVo);
	}

	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(Role role) {
		if (role.getId() != null) {
			return modify(currentService, role, "角色");
		} else {
			return add(currentService, role, "角色");
		}
	}

	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(currentService, keys);
	}

	@RequestMapping(value = "/editForm")
	public String editForm(Long id, HttpServletRequest request) {
		Role role;
		if (id != null) {
			role = currentService.findById(id);
			request.setAttribute("obj", role);
		}
		return "admin/role-form";
	}

	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult all() {
		return findByModel(currentService, null);
	}

	@RequestMapping(value = "/findRolePwoer")
	public @ResponseBody AjaxResult findRolePwoer(RolePwoer rolePwoer) {
		return new AjaxResult(AjaxResult.STATUS_OK, null, null, pwoerService.findByModel(rolePwoer), 0, 0);
	}

}